/* eslint-disable @typescript-eslint/no-unused-vars */
// Record<N, T> 返回以N类型为键，T类型为值的类型
interface Iperson {
    id: number;
    fullname: string;
    role: string;
}

// Pick<T, U> 返回包含 T类型中属于U类型的类型  与Omit相反
type P2 = { name: string; age: number };
type P3 = Pick<P2, 'name'>;
type p5 = Omit<P2, 'age'>;

//Partial<T> 返回T类型所有属性变为可选
type p4 = Partial<P2>;

const p: Record<number, Iperson> = {
    0: { id: 0, fullname: 'zht', role: 'admin' },
};
// console.log(p);

// Exclude 从联合类型T中排除掉U中包含的类型   与Extract相反
type EXCLUDE<T, U> = T extends U ? never : T;
type XIANGJUN = string | number;
type houdunren = string | number | boolean;
const x: EXCLUDE<houdunren, XIANGJUN> = true;
// console.log(x);

// 索引as类型断言
type User = { name: string; age: number; get(): void };
type FilterObjectProperty<T, U> = {
    [K in keyof T as Exclude<K, U>]: T[K];
};
type HD = FilterObjectProperty<User, 'name' | 'age'>;

// infer关键字 类型占位符
type Person = {
    name: string;
    age: number;
};
/*
   extractPerson 是一个推断类型， 如果T 满足 { name: infer U, age: number} 类型，那么返回 string，否则返回 unknown
*/
type extractPerson<T> = T extends { name: infer U; age: number } ? U : unknown;
type extractPerson1<T> = T extends { name: infer U; age: infer U }
    ? U
    : unknown;
type realType = extractPerson<Person>; // string
type realType1 = extractPerson1<Person>; // string | number

interface P1 {
    name: string;
    age: number;
}

type a = Pick<P1, 'name'>;
